package router

import (
	"gin/controller"
	"gin/pkg/logger"
	"github.com/gin-gonic/gin"
)

func InitRouter() *gin.Engine {
	r := gin.Default()

	r.Use(gin.LoggerWithConfig(logger.LoggerToFile()))
	r.Use(logger.Recover)

	param := r.Group("/param")
	{
		param.GET("/GetParam/:id", controller.ParamController{}.GetParam)
		param.GET("/GetParams/:cid/:name", controller.ParamController{}.GetParams)
		param.POST("/PostParam", controller.ParamController{}.PostParam)
		param.POST("/PostJsonParam", controller.ParamController{}.PostJsonParam)
		param.POST("/PostJsonByStructParam", controller.ParamController{}.PostJsonByStructParam)
	}

	exception := r.Group("/exception")
	{
		exception.POST("/Defer", controller.ExceptionController{}.Defer)
		exception.POST("/Panic", controller.ExceptionController{}.Panic)
		exception.POST("/Zero", controller.ExceptionController{}.Zero)
	}

	user := r.Group("/user")
	{
		user.GET("/GetUserInfo/:id", controller.UserController{}.GetUserInfo)
		user.POST("/list", controller.UserController{}.GetUserList)
		user.POST("/add", controller.UserController{}.AddUser)
		user.POST("/update", controller.UserController{}.UpdateUser)
		user.POST("/delete", controller.UserController{}.DeleteUser)

		user.POST("/register", controller.UserController{}.Register)
		user.POST("/login", controller.UserController{}.Login)
	}

	log := r.Group("/log")
	{
		log.GET("/Log", controller.LogController{}.Log)
	}

	player := r.Group("/player")
	{
		player.POST("/list", controller.PlayerController{}.GetPlayers)
	}

	vote := r.Group("/vote")
	{
		vote.POST("/add", controller.VoteController{}.AddVote)
	}

	r.POST("/ranking", controller.PlayerController{}.GetRanking)

	return r
}
